<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="author" content="zhaozhenguo">
<TITLE>卡片出库管理</TITLE>
<script LANGUAGE="javascript" src="../script/common.js" type="text/javascript"></script>
<script type="text/javascript" src="../script/print.js"></script>
<script language="javascript" type="text/javascript">
			//全局变量
			var org = Common.cOrg();	//当前单位	
			var qt = {};				//数据表格对象
			var cnt = {};
			var parentId;
			//页面加载方法
			function load(){ 
				Eui.showNavigation();
				searchForm.location.value = org.id;
				setPages(["listview","amply","detview","printBillDetail"]);
				parentId = org.parent?org.parent:0;
				
				DWR.call("storeQueryService.getOutTargetOrgs",function(result){
					Common.initDict("subordinate",result,"请选择","id","name");	
				})
				
				Common.initDict(cardOutForm.cardStatus,CardStore.getStoreStatus(),"请选择");	
				Common.initDict(searchForm.cardStatusId,CardStore.getStoreStatus(),"全 部");	
				
				Eui.initBeginDateInput("beginDateTd","起始日期","searchForm","beginDate","endDate","_pastDate");
				Eui.initEndDateInput("endDateTd","结束日期","searchForm","beginDate","endDate","_pastDate");
				
				createTable();	
			}  
			//生成表格，创建QueryTable对象(查询)
			function createTable(){
				var columns = [];
				columns[0] = {render:nameFunc};	
				columns[6] = {defOrder:true};													
				columns[7] = {title:"操作",width:"18%",render:operator,align:"center",order:false} 
				qt = new QueryTable("card_out_comfirm_query","searchForm","datalist",columns,{
					buttons:[
						{value:"添加出库单",actions:onNew}
					]
				});
			}
			function onNew(){
				$("cardOutForm").reset();
				switchPage('detview');
			}
			//处理数据 点姓名进入编辑页面
			function nameFunc(v,r){
				return "<a href=# onclick=\"onLook("+r[0]+");return false;\">"+v+"</a>"
			}
			function operator(v,r){
				var a = " <a href=# onclick=\"onCardOut("+r[0]+","+r[3]+","+r[7]+","+r[8]+");return false;\">出库</a>"
				var b = " <a href=# onclick=onEidt('"+r[0]+"','"+r[7]+"','"+r[8]+"')>修改</a>"
				var c = " <a href=# onclick=onDelete('"+r[0]+"')>删除</a>"
				var d = " <a href=# onclick=\"submit("+r[0]+","+r[3]+");return false;\">提交</a>"
				if(r[7] == parentId && (r[8]== Constants.CARDBILL_STATUS_NEW || r[8]== Constants.CARDBILL_STATUS_REJECTED)){
					return "<div>"+b+c+d+"</div>";
				}else if(r[8]== Constants.CARDBILL_STATUS_REQUEST){
					return "<div>"+b+c+"</div>";
				}else if(r[8]== Constants.CARDBILL_STATUS_PASSED){
					return "<div>"+c+a+"</div>";
				}else{
					return "<div>"+b+c+a+"</div>";
				}
				
			}
			function submit(id,amount){
				if(amount == 0){
					showInformation("提交数量不能为零!");return;
				}
				if(!(showQuestion("您确定提交吗?"))){
					return;
				}
				DWR.call("cardStoreService.submitDeliveryCardBill",id,function(){
					showInformation("提交成功!");
					qt.showTable();
					switchPage('listview');
				},{blockScreen:"true"});
			}
			function onCardOut(id,amount,destId,status){
				if(amount == 0){
					showInformation("出库数量不能为零!");return;
				}
				if(!(showQuestion("您确定出库吗?"))){
					return;
				}
				
				DWR.call("cardStoreService.confirmDelivery",id,function(result){
					showInformation("出库成功!");
					//Project.shopAutoInStore 是否自动入库
					if(Project.shopAutoInStore && result.dest.orgLevel == 700){
						DWR.call("cardStoreService.doConfirmWareHousing",id,result.dest.id,function(){
						})
					}
					//qt.showTable();
					//onEidt(id,destId,status)
					printBill(result.cardBill)
					switchPage('printBillDetail');
				},{blockScreen:"true"});
			}
			function onDelete(id){
				if(!(showQuestion("您确定删除吗?"))){
					return;
				}
				DWR.call("cardStoreService.deleteCardBill",id,1,function(){
					showInformation("删除成功!");
					qt.showTable();
					switchPage('listview');
				},{blockScreen:"true"});
			}
			//进入明细页面
			function onLook(id){
				switchPage("amply");
				requestframe.document.location.href = "card_bill_detail.html?cardBillId="+id+"&readOnly=true";
					
			}
			function onEidt(id,destId,status){
				switchPage("amply");
				var butCancel = "";
			
				if(destId == parentId && (status == Constants.CARDBILL_STATUS_NEW || status == Constants.CARDBILL_STATUS_REJECTED)){
					butCancel =  "<button type='button' onclick='submit()'>提 交</button>";
				}else if(status == Constants.CARDBILL_STATUS_REQUEST){
					butCancel =  " ";
				}else if(status == Constants.CARDBILL_STATUS_PASSED){
					butCancel =  "<button type='button' onclick='onCardOut()'>出 库</button>";;
				}else{
					butCancel =  "<button type='button' onclick='onCardOut()'>出 库</button>";
				}
				requestframe.document.location.href = "card_bill_detail.html?cardBillId="+id+"&butCancel="+butCancel+"&printDispaly=true";
			}
			function selCardType(){			
				var v = openDialogFrame("/basic/card_type_list.html?",'请选择卡片类型',464,700)
				if (v){
					$("cardOutForm").cardTypeId.value=v[0];
					$("cardOutForm").cardType.value = v[1];
					searchForm.cardType.value = v[1];
				}
			}
			function onSave(){
				if(!checkForm(cardOutForm))return;
				if(showQuestion("您确认要新建卡片出库单?")==true){
					var cardOutBill = Common.getValues(cardOutForm);
					var cardStatus = cardOutBill.cardStatus;
					var subordinate = cardOutBill.subordinate;
					DWR.call('cardStoreService.createCardBill', Constants.CARD_BILL_TYPE_OUT,cardOutBill.cardTypeId,cardStatus,subordinate,0,0,function(v){
						var client = v.cardBill;		
						client.cardType = v.cardType.name			
						cnt.cardBill = v.bill;
						var butCancel = "";
						
						if(client.acquirer == parentId && (client.status== Constants.CARDBILL_STATUS_NEW || client.status== Constants.CARDBILL_STATUS_REJECTED)){
							butCancel =  "<button type='button' onclick='submit()'>提 交</button>";
						}else if(client.status == Constants.CARDBILL_STATUS_REQUEST){
							butCancel =  " ";
						}else if(client.status == Constants.CARDBILL_STATUS_PASSED){
							butCancel =  "<button type='button' onclick='onCardOut()'>出 库</button>";;
						}else{
							butCancel =  "<button type='button' onclick='onCardOut()'>出 库</button>";
						}
						requestframe.document.location.href = "card_bill_detail.html?cardBillId="+client.id+"&butCancel="+butCancel;
						
						switchPage("amply");
					},{disCtrl:$('saveBut')});
				}
			}
			function showData(){
			  	qt.showTable();
			}
			function onBack(){
				searchForm.cardType.value = "";
				switchPage('listview');
				createTable()
				showData();
			}	
		</script>
</head>
<body onload="load()">
<!--页面导航-->
<div class="nav">
<div id="nav">&nbsp;</div>
</div>
<!--查询静态页面部分-->
<div id="listview">
<div class="searchForm">
<form id="searchForm" name="searchForm">
	<input type="hidden" id="location" name="location">
	<table cellSpacing=0 cellPadding=4 width="100%" border=0>
		<tr>
			<td><label>单据编号</label> <input type="text" name="outid" onblur="checkV(this,'number')" maxlength=12></td>
			<td><label>卡片类型</label> <input type="text" name="cardType"><a class="orga" title="请选择卡片类型" href="javascript:void(0)" onclick="selCardType()">&nbsp;&nbsp;</a></td>
			<td><label>卡片状态</label> <select name="cardStatusId"> <option></option> </select></td>
		</tr>
		<tr>
			<td id="beginDateTd"></td>
			<td id="endDateTd"></td>
			<td>
			<button type="button" onclick="showData()">查 询</button>
			</td>
		</tr>
	</table>
</form>
</div>
<div id="datalist"></div>
</div>
<div id="detview" style="display:none;">
<div class="form">
	<form id="cardOutForm" name="cardOutForm">
		<div class="formTitle">卡片出库</div>
		<table id="tbl" cellSpacing=0 cellPadding=4 width="100%" border=0>
			<input type="hidden" name="cardTypeId">
			<tr>
				<td><label>卡片类型</label> <input type="text" name="cardType" readonly class="readonly" onblur="checkV(this,'',true)"><a class="orga" title="请选择卡片类型" href="javascript:void(0)" onclick="selCardType()">&nbsp;&nbsp;</a><span class="des">*</span></td>
				<td><label>卡片状态</label> <select name="cardStatus" onblur="checkV(this,'',true)"><option></option></select><span class="des">*</span></td>
			</tr>
			<tr>
				<td><label>出库对象</label> <select name="subordinate"  onblur="checkV(this,'',true)" style="width:auto"><option></option></select><span class="des">*</span></td>
				
			</tr>
		</table>
	</form>
</div>
	<p>
		<button type="submit" id="saveBut" name="saveBut" onclick="onSave()">下一步</button>
		<button type="submit" id="returnBut" name="returnBut" onclick="switchPage('listview');">返 回</button>
	</p>
</div>
<div id="amply" style="display:none;">
	<iframe id="requestframe" name="requestframe" style="width:100%;height:93%;overflow:auto;" frameborder=0 src=""></iframe>
</div>
<div id="printBillDetail" class="form" style="display:none;">
	<div class="formTitle">
		<div class="l">单据预览</div>
		<div class="r">
			<button onclick="WebPrint.preview('content')">打印预览</button>
	 		<button onclick="WebPrint.print('content')">打印</button>
	 		<button onclick="onBack()">返回</button>
		</div>
	</div>
	<div  id="content" align='center'></div>
</div>
</body>
</HTML>
